var config={
    publicUrl:"http://localhost:3000/login",
};

function submitForm(){
    $('#login').form('submit',{
        onSubmit: function(){
            var isValid = $(this).form('validate');
            if (isValid){
                const data=$('#login').serializeJSON();
                $.ajax({
                    url:`${config.publicUrl}`,
                    method:"post",
                    xhrFields: {
                        withCredentials: true//解决跨域携带cookie
                    },
                    data
                }).then(res=>{
                    console.log(res);
                    if(res.data=="ok"){
                         window.localStorage.setItem("keys",res.key);
                         window.location.href="home.html"
                    }else{
                        $.messager.alert('提示','对不起账户或者密码错误,请重新输入');
                        $("#login").form("clear");
                    }
                });
            }
            return isValid;	// return false will stop the form submission
        }
    });
}